<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCouponsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('coupons', function (Blueprint $table) {
            $table->id();
            $table->string('name')->comment('优惠券名称');
            $table->string('color')->nullable()->comment('背景色hex');
            $table->decimal('unlock_price')->index()->comment('满足金额');
            $table->decimal('free_price')->index()->comment('减免金额');
            $table->tinyInteger('num_of_user')->default(1)->index()->comment('每人限领数量，0=不限');
            $table->tinyInteger('is_auto')->default(0)->index()->comment('是否自动领取：0=否，1=是');
            $table->tinyInteger('is_active')->default(0)->index()->comment('是否上架：0=否，1=是');
            $table->dateTime('start_use_at')->nullable()->index()->comment('生效时间');
            $table->dateTime('end_use_at')->nullable()->index()->comment('失效时间');
            $table->dateTime('stop_get')->nullable()->index()->comment('不可领取时间');
            $table->timestamps();
        });

        DB::statement("ALTER TABLE coupons comment '优惠券'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('coupons');
    }
}
